<template>
  <div class="fire-safety">
    <div class="fire-safety-main">
      <div class="fire-safety-title">
        <span class="title">消防安全</span>
        <span class="fire-total"><em>当前部署</em><i>178</i><i>/</i><i>230</i></span>
      </div>
      <div class="fire-safety-bg">
        <span :class="'BG'+index" v-for="(item,index) in fireSafetyData" :key="index" :style="{'width':setIBg(item.fireSafetyCount)}"></span>
      </div>
      <div class="fire-safety-list">
        <ul>
          <li v-for="(item,index) in fireSafetyData2" :key="index"><span :class="'BG'+index"></span><em>{{item.fireSafetyName}}</em><i>{{item.fireSafetyCount}}</i></li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      fireSafetyData: [
        {
          fireSafetyId: '01',
          fireSafetyName: '消防栓',
          fireSafetyCount: 98
        },
        {
          fireSafetyId: '02',
          fireSafetyName: '消防泵',
          fireSafetyCount: 62
        },
        {
          fireSafetyId: '03',
          fireSafetyName: '消防通道',
          fireSafetyCount: 48
        }
      ],
      fireSafetyData2: [],
      fireSafetyDataCount: 0
    }
  },
  mounted () {
    this.setCountData()
  },
  methods: {
    setCountData () {
      let count = 0
      let that = this
      this.fireSafetyData.forEach(function (item, index) {
        count += item.fireSafetyCount
        that.fireSafetyData2.push(item)
      })
      let obj = {
        fireSafetyId: '04',
        fireSafetyName: '总数',
        fireSafetyCount: count
      }
      this.fireSafetyData2.push(obj)
      this.fireSafetyDataCount = count
    },
    setIBg (n) {
      let count = this.fireSafetyDataCount
      let result = n / count * 100
      return parseInt(result) + '%'
    }
  },
  computed: {},
  watch: {}
}
</script>
<style lang="less" >
.fire-safety {
  width: 270px;
  background: rgba(43, 54, 72, 0.7);
  border-radius: 4px;
  height: 140px;
}
.fire-safety-main {
  padding: 16px 20px;
}
.fire-safety-title {
  height: 36px;
  position: relative;
  span.title {
    font-size: 12px;
    color: #ffffff;
    line-height: 20px;
  }
  span.fire-total {
    font-style: normal;
    position: absolute;
    right: 0;
    line-height: 20px;
    font-size: 14px;
    text-align: right;
    em {
      color: #aeaeae;
      padding: 0 10px;
      font-style: normal;
    }
    i {
      color: #50e3c2;
      font-style: normal;
    }
  }
}
.fire-safety-bg {
  height: 10px;
  letter-spacing: -5px;
  font-size: 0;
  width: 230px;
  span {
    letter-spacing: normal;
    box-sizing: border-box;
    vertical-align: top;
    display: inline-block;
    height: 10px;
    border-left: 1px solid rgba(43, 54, 72, 0.95);
    &:first-child {
      border-left: 0;
    }
    &.BG0 {
      background: #50e3c2;
    }
    &.BG1 {
      background: #4a90e2;
    }
    &.BG2 {
      background: #ffcb16;
    }
  }
}
.fire-safety-list {
  padding: 13px 0;
  ul {
    letter-spacing: -5px;
    font-size: 0;
    li {
      display: inline-block;
      letter-spacing: normal;
      vertical-align: top;
      font-size: 12px;
      color: #9facc3;
      height: 24px;
      line-height: 24px;
      width: 50%;
      span {
        display: block;
        float: left;
        width: 10px;
        height: 10px;
        border-radius: 2px;
        margin-top: 7px;
        margin-right: 10px;
        &.BG0 {
          background: #50e3c2;
        }
        &.BG1 {
          background: #00a5ed;
        }
        &.BG2 {
          background: #ffcb16;
        }
        &.BG3 {
          background: #c2c2c2;
        }
      }
      em {
        font-style: normal;
        width: 60px;
        display: block;
        float: left;
      }
      i {
        font-size: 14px;
        color: #50e3c2;
        font-style: normal;
      }
    }
  }
}
</style>
